/**
 * @auth: sce
 * @date: 1/9/18
 * @desc: 生成文件的增量包
 **/

const DiffMatchPatch = require('diff-match-patch');
const fs = require('fs');
const dmp = new DiffMatchPatch();

/**
 *
 * @param originalPath 原始文件路径
 * @param newPath 增量目标文件路径
 * @param patchPath 增量文件存放位置
 */
const patchFile = (originalPath, newPath, patchPath) => {
    const original = fs.readFileSync(originalPath);
    const newfile = fs.readFileSync(newPath);
    const patches = dmp.patch_make(original.toString(), newfile.toString());
    fs.writeFileSync(patchPath, patches);
};

module.exports = patchFile;